package com.lingkun.demo.utils;


import com.lingkun.demo.exception.code.BaseResponseCode;
import com.lingkun.demo.exception.code.ResponseCodeInterface;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class DataResult<T> {

    @ApiModelProperty(value = "响应状态码")
    private  int code;

    @ApiModelProperty(value = "响应提示语")
    private String msg;

    @ApiModelProperty(value = "响应数据")
    private T  data;

    public DataResult(){
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg  = BaseResponseCode.SUCCESS.getMsg();
        this.data = null;
    }

    public DataResult(T data){
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg  = BaseResponseCode.SUCCESS.getMsg();
        this.data = data;
    }

    public DataResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public DataResult(int code, T data) {
        this.code = code;
        this.msg = null;
        this.data = data;
    }

    public DataResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public DataResult(int code) {
        this.code = code;
        this.msg = null;
        this.data = null;
    }

    public DataResult(ResponseCodeInterface responseCodeInterface) {
        this.code = responseCodeInterface.getCode();
        this.msg = responseCodeInterface.getMsg();
        this.data = null;
    }

    public DataResult(ResponseCodeInterface responseCodeInterface, T data) {
        this.code = responseCodeInterface.getCode();
        this.msg = responseCodeInterface.getMsg();
        this.data = data;
    }

    public  static <T> DataResult getResult(int code, String msg, T data){
        return  new DataResult(code,msg,data);
    }

    public  static DataResult getResult(int code, String msg){
        return  new DataResult(code,msg);
    }

    public  static DataResult getResult(int code){
        return  new DataResult(code);
    }

    public  static <T> DataResult getResult(int code, T data){
        return  new DataResult(code,data);
    }

    public  static DataResult getResult(ResponseCodeInterface responseCodeInterface){
        return  new DataResult(responseCodeInterface);
    }

    public  static <T> DataResult getResult(ResponseCodeInterface responseCodeInterface, T data){
        return  new DataResult(responseCodeInterface,data);
    }

    public  static <T> DataResult success(T data){
        return  new DataResult(data);
    }

    public  static DataResult success(){
        return  new DataResult();
    }

}
